<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/header.css">
		<style type="text/css">
			.w {
				width: 90%;
				margin: 0px auto;
				margin-top: 120px;
				color: white;
			}

			.qrcode_style {
				background-color: rgba(0, 0, 0, 0.4);
				height: 500px;
				border-radius: 20px;
			}

			.qrcode_header {
				width: 100%;
				padding: 20px;
				background-color: rgba(0, 0, 0, 0.6);
				border-radius: 20px 20px 0px 0px;
			}

			.qrcode_header>img {
				vertical-align: middle;
				width: 48px;
				height: 48px;
				border-radius: 10px;
				margin-right: 20px;
				
			}

			.qrcode_centent {
				width: 100%;
				text-align: center;
			}

			.qrcode_centent>img {
				margin-bottom: 30px;
			}
		</style>
	</head>


	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<h1 class="mui-title">我的二维码</h1>
			<a id="download_qrcode" class="mui-pull-right" style="font-size: 16px;line-height: 46px;">
				<img src="../images/download.png" width="20px">
			</a>
		</header>


		<div class="w">
			<div class="qrcode_style">

				<div class="qrcode_header">
					<img id="faceImage">
					<span id="nickname"></span>
				</div>

				<div class="qrcode_centent">
					<img id="qrcode" src="../images/qrcode.png">
					<p>扫一扫加我好友</p>
				</div>


			</div>
		</div>



	</body>
	<script src="../js/mui.js"></script>
	<script src="../js/app.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		mui.init({
				swipeBack: true //启用右滑关闭功能
			});
		mui.plusReady(function(){
			var faceImage = document.getElementById("faceImage");
			var nickname = document.getElementById("nickname");
			var qrcode = document.getElementById("qrcode");
		
			var user = app.getUserGlobalInfo();
			faceImage.src = user.faceImage.substring(0, 4) === "http" ? user.faceImage : app.imgServerUrl + user.faceImage;
			nickname.innerText =  user.nickname;
			
			
			qrcode.width = document.body.clientWidth - 60;
			qrcode.hegiht = document.body.clientWidth - 60;
			qrcode.src = app.imgServerUrl+user.qrcode;
			
			
			//保存二维码
			document.getElementById("download_qrcode").addEventListener("tap",function(){
				plus.nativeUI.showWaiting("下载中...");
				
				var download = plus.downloader.createDownload(app.imgServerUrl+user.qrcode,{},function(d,status){
					if(status == 200){
						plus.nativeUI.closeWaiting();
						console.log("下载成功");
						plus.gallery.save(d.filename,function(){
							app.showToast("保存二维码图片成功","success");
						})
					}else{
						plus.nativeUI.closeWaiting();
						app.showToast("保存失败","error");
						console.log("保存失败");
					}
				});
				//启动下载任务
				download.start();
				
			})
			
		})
		
		
		
	</script>

</html>
